/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pt.ua.miect.sd.simuladorpesca.ui;

import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;

/**
 * Extends the defaultList Model with Generics
 * @author PedroA
 */
public class ListModel<T> extends DefaultListModel{

    public ListModel()
    {
        super();
    }

    /**
     * Adds an element to the listmodel
     * @param element
     */
    public void add(T element) {
        super.addElement(element);
    }

    /**
     * Gets an element at a specific position
     * @param position of the element
     * @return
     */
    public T getElement(int pos)
    {
        return (T)super.get(pos);
    }

    /**
     * Returns a List with all elements
     * @return
     */
    public List<T> getList()
    {
        List<T> list = new ArrayList<T>();
        for (int i = 0; i < this.size(); i++) {
            list.add((T)this.get(i));
        }
        return list;
    }

    /**
     * Adds a list of elements
     * @param list
     */
    public void setList(List<T> list)
    {
        for (T object : list) {
            this.add(object);
        }
    }




}
